[Fix] fix make_coord to require tuple arg and add crd2idx tests#251
[Fix] fix make_coord to require tuple arg and add crd2idx tests#251jli-melchior wants to merge 2 commits intomainfrom
Conversation
Change make_coord(*coord) to make_coord(coord) so that passing multiple args like make_coord(r, c) raises a clear TypeError instead of silently creating a wrong-rank coordinate. Update the one caller in kernels/layout_utils.py and add comprehensive pytest-compatible tests covering col-major, row-major, 1D, 3D layouts and error cases.
python/flydsl/expr/primitive.py
Outdated
|
|
||
| @traced_op | ||
| def make_coord(*coord, loc=None, ip=None): | ||
| def make_coord(coord, loc=None, ip=None): |
There was a problem hiding this comment.
make_coord doesn't only accept a tuple. It is the same as make_shape and make_stride. There is no need to change.
There was a problem hiding this comment.
so we can let make_coord not only accept a tuple, but also a variable-length arguments?
Revert make_coord to *args signature (consistent with make_shape and make_stride), but auto-unwrap a single tuple argument so both make_coord(r, c) and make_coord((r, c)) produce the same result. Update tests to verify both calling conventions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@jli-melchior shall we close this pr? |
Yes, we can close this PR for now because fx.make_coord is designed to accept variable-length arguments instead of a tuple.With this PR, we would support |
Motivation
Fixes #224
make_coord((r, c))(passing a tuple) causes a C++ assertion failure (coord.rank() == shape.rank()) inlayoutCrd2IdxTTTbecause*argswraps the tuple into((r, c),)— a rank-1 nested IntTuple instead of a flat rank-2 one. Users following thelayout_system_guide.mddocumentation hit this crash with no helpful error message.Technical Details
python/flydsl/expr/primitive.py: Keepmake_coord(*coord)varargs signature (consistent withmake_shapeandmake_stride), but auto-unwrap when a single tuple argument is passed. This makes both calling conventions work identically:make_coord(r, c)— varargs form (original)make_coord((r, c))— tuple form (now also supported)tests/unit/Layout/test_crd2idx.py: Add 6 pytest-compatible tests:test_crd2idx_col_major_tuple— verifiesmake_coord((r, c))tuple formtest_crd2idx_col_major_varargs— verifiesmake_coord(r, c)varargs formtest_crd2idx_col_major_both_forms_equal— verifies both forms produce identical resultstest_crd2idx_row_major— row-major (4,8) layouttest_crd2idx_1d— 1D layouttest_crd2idx_3d— 3D layoutTest Plan
Test Result
Submission Checklist
make_coord(r, c)still works,make_coord((r, c))now also worksmake_shapeandmake_strideAPI design